{% include 'QLGL/QLGL_index.html' %}

<div class="am-cf admin-main">
  {% include 'sidebar.html' %}
  <!-- content start -->
  <div class="admin-content">
    <div class="admin-content-body">
      <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">巡检业务>病害新增</strong></div>
      </div>
      <div class="am-g" style="position: absolute;height: 100%;right: 0px;left: 260px;width: auto;">

        {% include 'QLGL/XJYW/QLGL_XJYW_SIDEBAR.html' %}

        <div class="am-u-sm-10" style="position: absolute;width:auto;right:0;left: 200px;overflow-y: scroll;bottom: 100px;top: 0px;">
          <div class="am-u-sm-12 am-u-md-12">
            <div class="am-btn-toolbar">
              <div class="am-btn-group am-btn-group-xs">
                <button style="margin: 0 5px"  type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="back_to()">返回</button>
              </div>
            </div>
          </div>
          <!-- <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">天气情况</strong></div> -->
          <div class="am-g am-margin-top am-form-group">
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg"></strong></div>
          </div>

            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">天气：</div>
              <div class="am-u-sm-8 am-u-md-9" style="padding-left: 0rem;">
                {% if weatherinfo.weather == null %}
                <select data-am-selected="{btnSize: 'sm'}" id='txtWeather'>
                  <option value="晴">晴</option>
                  <option value="多云">多云</option>
                  <option value="小雨">小雨</option>
                  <option value="大雨">大雨</option>
                  <option value="下雪">下雪</option>
                  <option value="大风">大风</option>
                </select>
                {% else %}
                <div id="txtWeather" attr1="{{ weatherinfo.weather }}">{{ weatherinfo.weather }}</div>
                {% endif %}
              </div>

            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">温度：</div>
              <div class="am-u-sm-8 am-u-md-9" style="padding-left: 0rem;">
                {% if weatherinfo.temperature == null %}
                <input type="text"   class="am-input-lg" id='txtTemperature' min='-66' max='66'>℃
                {% else %}
                <div attr1="{{ weatherinfo.temperature }}" id="txtTemperature">{{ weatherinfo.temperature }}℃</div>
                {% endif %}
                
              </div>

            </div>
            <hr/>

            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">桥梁名称：</div>
              <div class="am-u-sm-8 am-u-md-9" style="padding-left: 0rem;">
                  <select data-am-selected="{btnSize: 'sm'}" id='bridge' name='bridge'>
                <option value="-1">--选择内容--</option>
                {% for i in bridgeinfo %}
                <option value="{{ i.bridge_id }}">{{ i.bridge_name }}</option>
                {% endfor %}
              </select>
              </div>

            </div>
            <hr/>

            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">巡查内容：</div>
              <div class="am-u-sm-8 am-u-md-9" style="padding-left: 0rem;">
                  <select data-am-selected="{btnSize: 'sm'}" id='txtCheckItem' name='txtCheckItem' onchange="CheckItemchange()">
                <option value="-1">--选择内容--</option>
                {% for i in dcitems %}
                <option value="{{ i.id }}">{{ i.name }}</option>
                {% endfor %}
              </select>
              </div>

            </div>
            <hr/>
            <div class="am-g am-margin-top">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">紧急程度：</div>
                <label class="am-radio-inline">
                <input type="radio" name="txtUrgencylevel" value="3" data-am-ucheck> 紧急
              </label>
            <label class="am-radio-inline">
              <input type="radio" name="txtUrgencylevel" value="2" data-am-ucheck> 一般
            </label>
            <label class="am-radio-inline">
              <input type="radio" name="txtUrgencylevel" value="1" data-am-ucheck> 另处
            </label>
            </div>

            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">病害详情：</div>
              <div class="am-u-sm-8 am-u-md-9" style="padding-left: 0rem;">
                  <select data-am-selected="{btnSize: 'sm'}" id='txtDiseaseId' name='txtDiseaseId'></select>
              </div>

            </div>
            <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">桩号位置：</div>
                <select data-am-selected="{btnSize: 'sm'}" id='txtPileD' name='txtPileD' required="">
              <option value="CT">CT</option>
              <option value="TC">TC</option>
            </select>
            </div>

            <hr/>
            <div class="am-g am-margin-top am-form-group">
            <div class="am-u-sm-4 am-u-md-3 am-text-right">桩号千米：</div>
            <div class="am-u-sm-8 am-u-md-9 am-u-end" style="padding-left: 0px;">
              <input type="text"  class="am-input-xl" id='txtPileKM' name='txtPileKM' required="">
            </div>
          </div>
          <hr/>
          <div class="am-g am-margin-top am-form-group">
            <div class="am-u-sm-4 am-u-md-3 am-text-right">桩号米：</div>
            <div class="am-u-sm-8 am-u-md-9 am-u-end" style="padding-left: 0px;">
              <input type="text"  class="am-input-xl" id='txtPileM' name='txtPileM' required="" min="0" max="999">
            </div>
          </div>
          <hr/>
            <div class="am-g am-margin-top am-form-group">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">备注信息：</div>
              <div class="am-u-sm-8 am-u-md-9 am-u-end" style="padding-left: 0px;">
                  <textarea rows="5" placeholder="请输入备注信息" id='txtRemark' name='txtRemark' required=""></textarea>
              </div>
            </div>
            <hr/>
            <div class="am-g am-margin-top">
              <div class="am-u-sm-4 am-u-md-3 am-text-right">媒体信息：</div>
                <input style="width:100px;height:36px;position:absolute;top:338px;left:942px;z-index: 1;opacity: 0;" name="myfile" id="f_fileXC" type="file" accept="image/*" multiple />
                <label>
                  <input id="XCXC" class="am-btn am-btn-primary am-btn-xs" type="button" value="拍照/相册" />
                </label>
            </div>


          <div class="am-g am-margin-top am-form-group">
            <ul class="am-avg-sm-2 am-avg-md-4 am-avg-lg-3 am-margin gallery-list" id='show'>
                <li></li>
            </ul>
          </div>
          <hr/>
          <div class="am-g am-margin-top am-form-group">
            <button class="am-btn am-btn-primary am-btn-xs" id='btnSeve' style="margin-left: 25%"  onclick="fromValid({{ taskid }})">提交</button>
           </div>
        </div>
      </div>
      
      <div class="am-g am-margin-top am-form-group">
        <input type="hidden" name='txtFileId' id='txtFileId'>
      </div>


    </div>
  </div>
</div>
</div>
</div>
{% include 'footer.html' %}
<!--[if lt IE 9]>
<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->

<!--[if (gte IE 9)|!(IE)]><!-->
<script src="/static/assets/js/jquery.min.js"></script>
<!--<![endif]-->
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/amazeui.tree.js"></script>
<script type="text/javascript" src="/static/assets/js/layer.js"></script>
<script src="/static/assets/datatables/amazeui.datatables.min.js"></script>
<script src="/static/assets/dialog/amazeui.dialog.min.js"></script>
<link rel="stylesheet" type="text/css" href="/static/assets/css/amazeui.tree.css" />
<script src="/static/assets/js/app.js"></script>
<style type="text/css">
  .li_a {
    color: #5c5c5c;
  }
</style>
<script type="text/javascript">
  $("#collapse-nav1").addClass("am-in");
  $("#qlgl").removeClass("am-collapsed");
  $("#qlglOxjyw").css("color", "#3399CC");
  $("#qlgl").css("color", "#3399CC");
  $("#xjywOrcxc").removeClass("li_a");

  $.ajaxSetup({
    data: {csrfmiddlewaretoken: '{{ csrf_token }}' },
  });
  function back_to(){
    window.history.back(-1);
  }
// $(window).load(function(){
//     // init();
// });

// var init = function(){
//     //存储信息
//     $('#txtTemperature').val({{ temperature }});
//     $('#txtWeather').val('{{ weather }}');
//     $('#txtTaskId').val({{ taskid }});
//     //绑定数据
//     var item = diseaseinfo[0];
//     $('#checkItem').append(item.checkItem);
//     $('#urgencylevel').append(item.urgency);
//     $('#disease').append(item.disease_name);
//     $('#piledirection').append(item.pile_direction+':K'+item.pile_km+'+'+item.pile_m);
//     // $('#pilekm').append(item.pile_km);
//     // $('#pilem').append(item.pile_m);
//     $('#txtCheckItem').val(item.param_id);
//     $('#txtDiseaseId').val(item.disease_id);
//     $('#txtUrgencylevel').val(item.urgency_level);
//     $('#txtPileD').val(item.pile_direction);
//     $('#txtPileKM').val(item.pile_km);
//     $('#txtPileM').val(item.pile_m);

// }

//   var init = function() {
//     //存储信息
//     $('#txtTemperature').val({{ temperature }});
//     $('#txtWeather').val('{{ weather }}');
//     $('#txtTaskId').val({{ taskid }});
//     if(diseaseinfo[0]) {
//       //console.log(diseaseinfo[0]);
//       //绑定数据
//       var item = diseaseinfo[0]
//       var urgency_level = item.urgency_level;
//       var param_partol_id = item.param_partol_id;
//       var param_name = item.param_name;
//       var disease_id = item.disease_id;
//       var disease_name = item.disease_name;
//       var pile_direction = item.pile_direction;
//       var pile_km = item.pile_km;
//       var pile_m = item.pile_m;
//       var checkitem = $("#selCheckItem");
//       var disease = $("#selDisease");
//       var piledir = $("#selPileDirection");
//       selectedOptions(checkitem, param_partol_id, param_name);
//       console.log(param_name + '-' + disease_name);
//       $("input[name='urgencylevel'][value='" + urgency_level + "']").attr("checked", true);
//       $("input[name='urgencylevel']").attr("disabled", "disabled")
//       $("#hidurgencylevel").val(urgency_level)
//       setTimeout(function() {
//         selectedOptions(disease, disease_id, disease_name);
//       }, 1000);

//       selectedOptions(piledir, pile_direction, pile_direction);
//       checkitem.selected('disable');
//       disease.selected('disable');
//       piledir.selected('disable');
//       $("#btnpilekm").val(pile_km).attr("disabled", "disabled");
//       $("#btnpilem").val(pile_m).attr("disabled", "disabled");
//       $("#hidpilekm").val(pile_km)
//       $("#hidpilem").val(pile_m)
//       // 默认类型为巡查任务状态为1，如果有病害信息，肯定为维护任务，状态为2
//       $("#hidtasktype").val('2')

//     }
//   }

// var test = function(){
//     alert($('#txtTaskId').val());
// }

function CheckItemchange(){
  var txtCheckItem = $("#txtCheckItem option:selected").val();
  var sel = $('#txtDiseaseId');
  sel.empty();
  if(txtCheckItem == -1) return;
    $.ajax({
      "url": '/checkItemDetailJson/?cid=' + txtCheckItem,
      "datatype": "json",
      "type": "get",
      "success": function(result) {
        if(result.status == 1) {

          var data = eval(result.data);
          $.each(data, function(i, item) {
            sel.append("<option value='" + item.disease_id + "'>" + item.disease_name + "</option>");
          });
        } else {
          console.log('error')
        }
      },
      "error": function(err, result) {
        if(err.length != 0) {
          console.log(result);
          return;
        }
      }
    });

}



var upimg = document.querySelector('#f_fileXC');
upimg.addEventListener('change', function(e){
    var files = this.files;
    if(files.length){
        if(checkFile(files))
        {
            uploadFiles(files);
        }
    }
});

function checkFile(files){
    for(var i=0; i<files.length; i++){
        if( !files[i].type.match(/.jpg|.jpeg|.gif|.png|.bmp/) ){  //判断上传文件格式
            AlertMSG('上传的图片格式不正确')
            return false;
        }
    }
    return true;
}

$("#XCXC").click(function () {
      $("#f_fileXC").click();
})

var fromValid = function(txtTaskId){
      // var txtTaskId = $("#txtTaskId").val();
      var txtWeather = $("#txtWeather option:selected").val();
      if(txtWeather == undefined){
        txtWeather = $("#txtWeather").attr("attr1");
      }
      var txtTemperature = $("#txtTemperature").val();
      if(txtTemperature == ''){
        txtTemperature = $("#txtTemperature").attr("attr1");
      }
      var bridge = $("#bridge option:selected").val();
      var txtCheckItem = $("#txtCheckItem option:selected").val();
      var txtDiseaseId = $("#txtDiseaseId option:selected").val();
      var txtRemark = $("#txtRemark").val();
      var txtUrgencylevel = $("input:radio[name='txtUrgencylevel']:checked").val();
      var txtPileD = $("#txtPileD").val();
      var txtPileKM = $("#txtPileKM").val();
      var txtPileM = $("#txtPileM").val();
      var txtFileId = $("#txtFileId").val();

      if(txtTemperature == ''){
        AlertMSG("请填写温度！")
      }else if(bridge == -1){
        AlertMSG("请选择巡查桥梁！")
      }else if(txtCheckItem == -1){
        AlertMSG("请选择巡查内容！")
      }else if(txtDiseaseId == undefined){
        AlertMSG("请选择病害详情！")
      }else if(txtUrgencylevel == undefined){
        AlertMSG("请选择紧急程度！")
      }else if(txtPileKM == ''){
        AlertMSG("请填写桩号千米！")
      }else if(txtPileM == ''){
        AlertMSG("请填写桩号米！")
      }else{

      $.ajax({
      "url":"/QLXJ_XJYW_RCXJ_RECORD_ADDSAVE/",
      "data":{"txtTaskId":txtTaskId,"txtWeather":txtWeather,"txtTemperature":txtTemperature,"txtCheckItem":txtCheckItem,"txtDiseaseId":txtDiseaseId,"txtRemark":txtRemark,"txtUrgencylevel":txtUrgencylevel,"txtPileD":txtPileD,"txtPileKM":txtPileKM,"txtPileM":txtPileM,"txtFileId":txtFileId,"bridge_id":bridge},
      "datatype":"json",
      "type":"post",
      "async":"false"
      }).success(function(data){
        if (data.status == 1) {
          // alert("保存成功！")
          
          window.location="/QLXJ_XJYW_RCXJ_SEE/?task_id="+txtTaskId+""


        } else {
          AlertMSG(data.message)
        }
      }).error(function(data){
        AlertMSG("保存失败！")
      });


      }
}
var uploadFiles = function(files){
    var form_data = new FormData();
    for(var i=0; i< files.length; i++){
        form_data.append("myfile" , files[i] );
    }
    // 提交ajax的请求

    $.ajax({
        url:"/uploadFile_XC/",
        type:'POST',
        data: form_data,
        processData: false,  // tell jquery not to process the data
        contentType: false, // tell jquery not to set contentType
        success: function(result) {
            console.log(result.data)
            if (result.status == 1){
                var show = $("#show");
                // show.css("display","block");
                var html = '',ids = '';
                var fileIds = $('#txtFileId');
                for(var i = 0 ;i<result.data.length;i++){
                    var f = result.data[i];
                    html += '<li><img class="am-img-thumbnail am-img-bdrs" src="'+f.file_url+'" alt="img"></li>';
                    ids += f.file_id+'|'
                    // console.log(f.file_url);
                }
                fileIds.val(ids);
                show.html(html);
            }
        }
    });
}
var AlertMSG=function(msg){
    AMUI.dialog.alert({ title: '错误提示', content: msg, onConfirm: function() { console.log('close'); } });
}
</script>

</body>

</html>